home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / CH2 / FermentedFruit.cs next >
Text File  |  2006-05-29  |  2KB  |  62 lines

  1. // ========================================================================
  2. //  FermentedFruit.cs
  3. //
  4. //  Solution to the anti-optimization challenge
  5. //  this uses no loops at all
  6. // ========================================================================
  7.  
  8. function runFermentedFruit()
  9. // ----------------------------------------------------
  10. //     Entry point for the program.
  11. // ----------------------------------------------------
  12. {
  13.  //
  14.  // ----------------- Initialization ---------------------
  15.  //
  16.  
  17.  %costBananas = 1.15; // initilize the price values
  18.  %costApples = 0.55;
  19.  %costOranges = 0.55;
  20.  %costMangos = 1.90;
  21.  %costPears = 0.68;
  22.  
  23.  %quantityBananas = 1; // initilize the quantity values
  24.  %quantityApples  = 3;
  25.  %quantityOranges = 4;
  26.  %quantityMangos  = 1;
  27.  %quantityPears   = 2;
  28.  
  29.  %numFruit=0;     // always a good idea to initialize *all* variables!
  30.  %totalCost=0;    // (even if we know we are going to change them later)
  31.  
  32.  //
  33.  // ----------------- Computation ---------------------
  34.  //
  35.  
  36.  // Display the known statistics of the fruit collection
  37.  
  38.    echo("Cost of bananas:$" @ %costBananas);
  39.    echo("Number of bananas:" @ %quantityBananas);
  40.    echo("Cost of apples:$" @ %costApples);
  41.    echo("Number of apples:" @ %quantityApples);
  42.    echo("Cost of oranges:$" @ %costOranges);
  43.    echo("Number of oranges:" @ %quantityOranges);
  44.    echo("Cost of mangos:$" @ %costMangos);
  45.    echo("Number of mangos:" @ %quantityMangos);
  46.    echo("Cost of pears:$" @ %costPears);
  47.    echo("Number of pears:" @ %quantityPears);
  48.  
  49.  // count up all the pieces of fruit and calculate the total cost
  50.    %numFruit = %quantityBananas + %quantityApples + %quantityOranges
  51.                + %quantityMangos + %quantityPears;
  52.    %totalCost = (%costBananas * %quantityBananas) +
  53.                 (%costApples  * %quantityApples)  +
  54.                 (%costOranges * %quantityOranges) +
  55.                 (%costMangos  * %quantityMangos)  +
  56.                 (%costPears   * %quantityPears);
  57.  
  58.  // now echo the totals
  59.  echo("Total pieces of Fruit:" @ %numFruit);
  60.  echo("Total Price of Fruit:$" @ %totalCost);
  61. }
  62.